﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using InstituteManager.Data;
using System.Data;

namespace InstituteManager.Bussiness
{
    public static class AwardBL
    {
        public static string errorMsg = "";
        public static List<tbl_Award> getByAll()
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();
            List<tbl_Award> compe = InsMana.tbl_Award.ToList();
            return compe;
        }

        public static tbl_Award getById(int Id)
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();
            return InsMana.tbl_Award.First(temp => temp.AwardId == Id);
        }

        public static bool AddNew(tbl_Award com)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                InsMana.AddTotbl_Award(com);
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message + e.StackTrace;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static bool Update(tbl_Award com)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                tbl_Award compe = InsMana.tbl_Award.First(temp => temp.AwardId == com.AwardId);
                compe.AwardName = com.AwardName;
                compe.Worth = com.Worth;
                compe.Description = com.Description;
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static bool Delete(int Id)
        {
            try
            {
                InstituteManagerEntities InsMana = new InstituteManagerEntities();
                InsMana.DeleteObject(InsMana.tbl_Award.First(temp => temp.AwardId == Id));
                InsMana.SaveChanges();
            }
            catch (Exception e)
            {
                errorMsg = e.Message;
                return false;
            }
            errorMsg = "";
            return true;
        }

        public static List<tbl_Award> SearchByName(string AwardName)
        {
            InstituteManagerEntities InsMana = new InstituteManagerEntities();

            return (from sc in InsMana.tbl_Award where sc.AwardName.Contains(AwardName) select sc).ToList<tbl_Award>();
        }
    }
}
